home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_348 / colorreq / popcolor.asm < prev    next >
Assembly Source File  |  1992-05-06  |  6KB  |  262 lines

  1. ;***************************** PopColor.asm ****************************
  2. ; This utility, when executed, waits a few seconds for the user to re-
  3. ; arrange a desired screen to the front of the display. Then the dissidents
  4. ; ColorTool is opened on that screen, allowing the user to adjust the
  5. ; colors. The dissidents color.library must be in the libs drawer of the
  6. ; boot disk.
  7. ;
  8. ; Assemble this file and link
  9. ; 1> blink PopColor.o small.lib nodebug to ram:PopColor
  10.  
  11.     SMALLOBJ
  12.     OPTIMON
  13.     OBJFILE "rad:Color.o"
  14.  
  15.     SECTION ColorCode,CODE
  16.  
  17.     INCLUDE    "rad:FileIO.i"
  18.  
  19.     XREF    _LVOOldOpenLibrary,_LVOCloseLibrary
  20.     XREF    _LVOWaitPort,_LVOGetMsg,_LVOReplyMsg
  21.     XREF    _LVODelay,_LVOOutput,_LVOWrite,_LVODisplayAlert,_LVORead
  22.     XREF    _LVOOpen,_LVOClose
  23.  
  24. _LVODoColor    equ    -30
  25.  
  26. TDNestCnt    equ    295
  27. ThisTask        equ    $114
  28. pr_CLI        equ    $AC
  29. pr_MsgPort    equ    $5C
  30.  
  31.     XDEF    _startup
  32. _BUFFER:
  33. _startup:
  34.     ;---Get Exec library base
  35.         movea.l    $00000004,a6
  36.         movea.l    a6,a4            ;_SysBase
  37.     ;---Open the DOS library
  38.         lea        DOSName,a1
  39.         jsr        _LVOOldOpenLibrary(a6)
  40.         movea.l    d0,a5
  41.     ;---Open the Intuition library
  42.         lea        IntuiName,a1
  43.         jsr        _LVOOldOpenLibrary(a6)
  44.         movea.l  d0,a3
  45.     ;---get the address of our task
  46.         movea.l    ThisTask(a6),a2 
  47.     ;---are we running as a son of Workbench?
  48.         moveq        #0,d7
  49.         move.l    pr_CLI(a2),d0
  50.         bne.s        doMN
  51.     ;---WorkBench: wait for a message from our starter
  52.         ;[a2=ThisTask]
  53.         ;[a5=_DOSBase]
  54.         lea        pr_MsgPort(a2),a0
  55.         jsr        _LVOWaitPort(a6)
  56.         lea        pr_MsgPort(a2),a0
  57.         jsr        _LVOGetMsg(a6)
  58.     ;---save the message so we can return it later
  59.         move.l    d0,d7
  60. doMN    bra        domain
  61.  
  62. IntuiName    dc.b    'intuition.library',0
  63. DOSName        dc.b    'dos.library',0
  64. ColorErr        dc.b    'Need the dissidents '
  65. ColorName    dc.b    'color.library',0
  66. ReqErr        dc.b    'Need the dissidents '
  67. ReqName        dc.b    'requester.library',0
  68. NoMem            dc.b    'Out of memory',0
  69.  
  70.     CNOP    0,2
  71. req_err:
  72.         lea        ReqErr,a1
  73.         bra.s        dsp_err
  74. fil_err:
  75.         lea        NoMem,a1
  76.         bra.s        dsp_err
  77. col_err:
  78.         lea        ColorErr,a1
  79. ;This makes an alert message out of the passed string in a1
  80. ;and displays it as an alert or CLI msg. 79 chars MAX in passed string.
  81. ;wb msg in d7, DOSBase in a5, IntuitionBase in a3
  82. dsp_err:
  83.         suba.w    #256,sp
  84.         movea.l    sp,a0
  85.         addq.l    #2,a0            ;for WB, skip X pos
  86.         moveq        #20,d0
  87.         move.b    d0,(a0)+        ;y co-ordinate = 20
  88.         move.l    a0,d2
  89.   ;---copy passed string to BUFFER and get numOfChars
  90.         movea.l    a1,a6
  91. lenS    move.b    (a6)+,(a0)+
  92.         bne.s        lenS
  93.         subq.l    #1,a6
  94.         suba.l    a1,a6            ;numOfChars
  95.   ;---If the CLI, write the msg there
  96.         move.l    d7,d1            ;wb msg
  97.         bne.s        WBalert
  98.         clr.b        (a0)
  99.         moveq        #10,d0
  100.         move.b    d0,-(a0)
  101.         move.l    a6,d3
  102.     ;---get standard output handle
  103.         movea.l    a5,a6
  104.         jsr        _LVOOutput(a6)
  105.         move.l    d0,d1
  106.   ;---add new line char
  107.         addq.l    #1,d3
  108.         jsr        _LVOWrite(a6)
  109. fail_out:
  110.         adda.w    #256,sp
  111.         bra        faIL
  112.   ;---If WB, post an alert
  113. WBalert:
  114.         clr.b        (a0)            ;continuation byte = 0
  115.         moveq        #80-1,d1        ;80 chars - 1 Dbra
  116.         sub.l        a6,d1
  117.         bcc.s        aler
  118.         moveq        #1,d1
  119. aler    lsr.l        #1,d1
  120.         lsl.w        #3,d1
  121.         movea.l    d2,a0
  122.         subq.l    #3,a0
  123.         move.w    d1,(a0)        ;x co-ordinate = (numOfChars/2) * 8 (WORD)
  124.     ;---display the alert
  125.         moveq        #50,d1        ;Height
  126.         moveq        #0,d0            ;RECOVERY_ALERT
  127.         movea.l    a3,a6
  128.         jsr        _LVODisplayAlert(a6)
  129.         bra.s        fail_out
  130.  
  131. domain:
  132.         suba.l    a2,a2
  133.         moveq        #0,d5
  134.     ;---Open the dissidents color library
  135.         lea        ColorName,a1
  136.         jsr        _LVOOldOpenLibrary(a6)
  137.         move.l    d0,d6
  138.         beq.s        col_err
  139.     ;---Open the dissidents requester library
  140.         lea        ReqName,a1
  141.         jsr        _LVOOldOpenLibrary(a6)
  142.         move.l    d0,d5
  143.         beq        req_err
  144.     ;---Get a FileIO
  145.         movea.l    d5,a6
  146.         jsr        _LVOGetFileIO(a6)
  147.         move.l    d0,d1
  148.         beq        fil_err
  149.         movea.l    d0,a2
  150.         lea        _BUFFER,a1
  151.         move.l    a1,FILEIO_BUFFER(a2)
  152.         lea        TableToLoad,a1
  153.         move.l    a1,FILEIO_TITLE(a2)
  154.     ;---give the user time to rearrange the screens
  155.         moveq        #127,d1
  156.         add.w        d1,d1
  157.         movea.l    a5,a6
  158.         jsr        _LVODelay(a6)
  159.     ;---See if user has a ColorTable to load
  160.         bsr        DoFile
  161.         beq.s        doDD
  162.         move.l    FILEIO_FILESIZE(a2),d2
  163.         beq.s        doDD
  164.     ;---Load ColorTable
  165.         move.w    #1005,d2
  166.         bsr        OpenFile
  167.         move.l    d0,d2
  168.         beq.s        doDD
  169.         moveq        #32*2,d3
  170.         lea        CTable,a1
  171.         move.l    a1,d2
  172.         jsr        _LVORead(a6)
  173.         move.l    d4,d1
  174.         jsr        _LVOClose(a6)
  175.     ;We get the address of front screen from Intuition. This will work until
  176.     ;1.4 (IntuitionBase disappears then).
  177.     ;NOTE - We assume that someone doesn't close that screen before we write
  178.     ;out its ColorTable. We really should do a Forbid/Permit around this whole
  179.     ;bloody thing. What the hell. We wouldn't need this utility if other
  180.     ;programmers used the color library anyway.
  181.     ;---open the color tool window on this screen
  182. doDD    movea.l    60(a3),a1    ;the dreaded screen
  183.         movea.l    44+4(a1),a0
  184.         addq.l    #4,a0
  185.         move.l    (a0),d3        ;its ColorTable
  186.         movea.l    d2,a0            ;0 or the loaded ColorTable
  187.         movea.l    d6,a6
  188.         jsr        _LVODoColor(a6)
  189.     ;---See if user wants to save the screen's ColorTable
  190.         lea        TableToSave,a1
  191.         move.l    a1,FILEIO_TITLE(a2)
  192.         bsr.s        DoFile
  193.         beq.s        faIL
  194.         move.w    #1006,d2
  195.         bsr        OpenFile
  196.         beq.s        faIL
  197.         moveq        #32*2,d2
  198.         exg.l        d2,d3
  199.         jsr        _LVOWrite(a6)
  200.         move.l    d4,d1
  201.         jsr        _LVOClose(a6)
  202.     ;---Free the FileIO
  203. faIL    tst.l        d5
  204.         beq.s        clC
  205.         movea.l    a2,a1
  206.         movea.l    d5,a6
  207.         jsr        _LVOReleaseFileIO(a6)
  208.         movea.l    a4,a6
  209.         movea.l    d5,a1
  210.         jsr        _LVOCloseLibrary(a6)
  211.     ;---close the color library
  212. clC    movea.l    a4,a6
  213.         tst.l        d6
  214.         beq.s        clI
  215.         movea.l    d6,a1
  216.         jsr        _LVOCloseLibrary(a6)
  217.     ;---close Intuition library
  218. clI    movea.l    a3,a1
  219.         jsr        _LVOCloseLibrary(a6)
  220.     ;---close DOS library
  221.         movea.l    a5,a1
  222.         jsr        _LVOCloseLibrary(a6)
  223.     ;---if we ran from CLI, skip workbench cleanup
  224.         move.l    d7,d0
  225.         beq.s        exitToDOS
  226.     ;------ return the startup message to our parent
  227.     ;------ we forbid so workbench can't UnLoadSeg() us
  228.     ;------ before we are done
  229.         addq.b    #1,TDNestCnt(a6)
  230.         ;[d0=returnMsg]
  231.         movea.l    d0,a1
  232.         jsr        _LVOReplyMsg(a6)
  233.     ;---this rts sends us back to DOS
  234. exitToDOS:
  235.         moveq        #0,d0
  236.         rts
  237.  
  238. DoFile:
  239.         movea.l    60(a3),a1
  240.         movea.l    d5,a6
  241.         movea.l    a2,a0
  242.         jsr        _LVODoFileIOWindow(a6)
  243.         move.l    d0,d2
  244.         beq.s        fff
  245.         addq.l    #1,d2
  246. fff    rts
  247.  
  248. OpenFile:
  249.         ext.l        d2
  250.         move.l    d0,d1
  251.         movea.l    a5,a6
  252.         jsr        _LVOOpen(a6)
  253.         move.l    d0,d1
  254.         move.l    d0,d4
  255.         rts
  256.  
  257. CTable            ds.w    32
  258. TableToLoad        dc.b    'Load ColorTable. CANCEL if none',0
  259. TableToSave        dc.b    'Save ColorTable. CANCEL if none',0
  260.  
  261.     END
  262.